import type { RouteRecordRaw } from 'vue-router'
import type { App } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import { setupRouterGuard } from './guard'

const routes: RouteRecordRaw[] = [
  {
    path: _ViewPath.Login,
    component: () => import('@/views/common/Login.vue')
  },
  {
    path: _ViewPath.Index,
    redirect: _ViewPath.Home,
    component: () => import('@/views/layout/Index.vue'),
    children: [
      {
        path: _ViewPath.Home,
        name: _ViewName.Home,
        component: () => import('@/views/common/Home.vue')
      },
      {
        path: _ViewPath.About,
        name: _ViewName.About,
        component: () => import('@/views/common/About.vue')
      },
      {
        path: _ViewPath.Userprofile,
        name: _ViewName.Userprofile,
        component: () => import('@/views/common/userprofile/Index.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router

export const setUpRouter = async (app: App) => {
  setupRouterGuard(router)
  app.use(router)
}
